// 加密
var Byte = require('Byte');
var ProtocolType = require('ProtocolType');

module.exports = cc.Class({
    properties: {
        byte: null,
        tempBuffer: null,
    },
    ctor(){
        this.byte = new Byte();
        this.tempBuffer = new Byte();
    },
    writeInt(value){
        this.byte.writeByte(value);
    },

    writeBoolean(){

    },
    writeLong(){

    },
    getBuffer(){
        return this.byte.getBuffer();
    },
    getBinaryString(){
        return this.byte.getBinaryString();
    },
    getBinaryLen(){
        return this.byte.length;
    },
    writeString(value){
        if (value == null) {
            this.byte.writeByte(ProtocolType.ArgTypeNull);
        } else {
            value += "";
            // 数据类型
            this.byte.writeByte(ProtocolType.ArgTypeString);

            this.tempBuffer.length = 0;
            this.tempBuffer.pos = 0;
            this.tempBuffer.writeUTFBytes(value);
            // 数据长度
            var dataLen = this.tempBuffer.length;
            // todo 在fb中找一下＋4的原因
            this.writeInt(dataLen + 4);
            this.byte.writeArrayBuffer(this.tempBuffer.getBuffer(), 0, dataLen);
        }
    },

});